﻿using Microsoft.AspNetCore.Http;
using SBlogCore.Application.UploadFileManager.IServices;
using SBlogCore.Common.FileUploadExtend;

namespace SBlogCore.Application.UploadFileManager.Serivices
{
    /// <summary>
    /// 
    /// </summary>
    public class UploadFileService : IUploadFileService
    {
        private readonly FileUploadFactory _saveFile;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="saveFile"></param>
        public UploadFileService(FileUploadFactory saveFile)
        {
            this._saveFile = saveFile;
        }
        /// <summary>
        /// 批量保存文件
        /// </summary>
        /// <param name="files"></param>
        /// <returns></returns>
        public async Task<List<string>> SaveMoreFile(List<IFormFile> files)
        {
            var paths = new List<string>();
            foreach (var file in files)
            {
                var uploadHandler = _saveFile.GetInstance();
                await uploadHandler.SaveAsync(file);
                var path = uploadHandler.WebPath;
                paths.Add(path);
            }
            //返回保存文件的相对地址
            return paths;
        }
    }
}
